<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/login.css">
    <script src="js/jquery-3.5.1.js"></script>
    <script>
        function check(){
            if ($("#adminName").val()=="" || $("#password").val()==""){
                return false;
            }else {
                return true;
            }
        }
    </script>
    <script>
        $(function (){
            $("#btn_img").click(function (){
                if (check() == true){
                    $.ajax({
                        type:"post",
                        url:"LoginServlet",
                        data:{
                            adminName:$("#adminName").val(),
                            password:$("#password").val()
                        },
                        success:function(result){
                            if(result=="1"){
                                window.location.href="main.html";
                            }
                            else if(result=="0"){
                                alert("账号或密码错误,登录失败");
                            }
                            else if(result=="2"){
                                alert("用户已被锁定,请联系管理员");
                            }
                        },
                        error:function (){
                            alert("error")
                        }
                    })
                }else {
                    alert("账号或密码不能为空")
                }
            })
        })
    </script>
</head>

<body>
<div id="div_center">
    <div id="div_inputbox">
        <input type="text" id="adminName"/>
        <input type="password" id="password"/>
    </div>
    <input id="btn_img" type="image" src="images/bg_login_btn.jpg"/>
</div>
</body>

</html>
